/***************************************************************************
 *   Copyright (C) 2007 by Ivan Vasić   				       			   *
 *   ivasic@gmail.com   								   				   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef BENCODER_H
#define BENCODER_H
		
#include <QtGlobal>

class QByteArray;
class QString;

/**
 * @class BEncoder
 * @brief B-Koder (B-Encoder) klasa.
 * @author Ivan Vasić<ivasic@gmail.com>
 * 
 * Služi za kodiranje podataka koristeći B-Encoding. Za više detalja oko načina kodiranja pogledati http://www.bittorrent.org/
*/
class BEncoder
{
	public:
		///Konstruktor		 
		BEncoder();
		///Destruktor
		~BEncoder();
		
		
		/**
		 * @brief Započinje novu listu (list).
		 * @warning Ova funkcija @e mora da ima odgovarajući poziv BEncoder::end() !
		 */
		void beginList();
		
		/**
		 * @brief Započinje novi rečnik (dictionary).
		 * @warning Ova funkcija @e mora da ima odgovarajući poziv BEncoder::end() !		 
		 */
		void beginDict();
		
		/**
		 * @brief Završava započetu listu ili rečnik.
		 * @see BEncoder::beginDict(), BEncoder::beginList()
		 */
		void end();
		
		/**
		 * @brief Upisuje novi integer u izlaz.
		 * 
		 * Integeri se kodiraju prefiksom 'i' i sufiksom 'e'. Za više detalja pogledati http://www.bittorrent.org/
		 * 
		 * @see BEncoder::write()
		 */
		void writeUInt(quint32 val);
		
		/**
		 * @brief Upisuje novi integer64 u izlaz.
		 * 
		 * Integeri se kodiraju prefiksom 'i' i sufiksom 'e'. Za više detalja pogledati http://www.bittorrent.org/

		 */
		void writeUInt64(quint64 val);
		
		/**
		 * @brief Upisuje novi string u izlaz.
		 * 
		 * Stringovi se kodiraju prefiksom dužina stringa praćen delimiterom ':' i sufiksom koji je u stvari sam string. Za više detalja pogledati http://www.bittorrent.org/.<br><br>
		 * @b Primer:
		 * String "test" se kodira kao: 4:test<br>
		 * String "primer" se kodira kao: 6:primer
		 */
		void writeString(const QByteArray& val);
		
		/**
		 * @brief Vraća izlazni stream.
		 * @returns QByteArray* izlazni stream
		 * @todo Dodaj više tipova izlaznih streamova
		 **/
		QByteArray* getData() { return out; }
		

	private:
		QByteArray* out;
};

#endif
